<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户登录</title>
    <script src="js/base.js"></script>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
        }
        h1 {
            font-size: 2em;
            color: #333;
            text-align: center;
            margin-bottom: 20px;
        }
        input[type="text"], input[type="password"] {
            width: 30%;
            padding: 10px;
            margin: 10px 0;
            border: 1px solid #ccc;
            border-radius: 5px;
            font-size: 14px;
        }
        button {
            padding: 10px 20px;
            margin: 5px;
            background-color: #007BFF;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 14px;
        }
        button:hover {
            background-color: #0056b3;
        }
        .button-group {
            display: flex;
            justify-content: center;
            gap: 10px; /* 按钮之间的间距 */
        }
    </style>
</head>
<body>
    <h1>用户登录</h1>
 用户名：<input type="text" id="username"/><br/>
 密码：<input type="password" id="password"/><br/>
    <div class="button-group">
<button onclick="onSignInClick();">登录</button><button onclick="goSignUpClick();">注册</button>
    </div>
        <script>
    function onSignInClick(){
        let url="http://localhost:8080/user/signIn";
        let method="post";
        let json={};
        json.username = document.getElementById('username').value;
        json.password = document.getElementById('password').value;
        $.rest(url,method,json,function(r){
            if (r.code==200){

                let teacher=r.data;
                let tid=teacher.id;
                let tname=teacher.name;
                localStorage.setItem("tid",tid);
                localStorage.setItem("tname",tname);
                window.location.href="teacherIndex.html";
            }else if(r.code==201){
                let student=r.data;
                let sid=student.id;
                let sname=student.name;
                localStorage.setItem("sid",sid);
                localStorage.setItem("sname",sname);
                window.location.href="studentIndex.html";

            }else{
                alert("登录信息有误");            }
        });
    }
    function goSignUpClick(){
        window.location.href="signUp.html";
    }



</script>
</body>
</html>